package com.shenzhenai.dn_compose_learn

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.shenzhenai.dn_compose_learn.ui.theme.DN_Compose_LearnTheme

/**
 *
 * 06-Material Design
 * https://www.bilibili.com/video/BV1ob4y1a7ad?spm_id_from=333.788.player.switch&vd_source=e07cc8cc94eb22bd76722071b03cd199&p=6
 *
 *
 *
 */
class MainActivity05 : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            DN_Compose_LearnTheme{
                MessageCard(
                    Message("Android", "Jetpack Compose")
                )
            }
        }
    }

    @Composable
    fun MessageCard(msg: Message) {
        /**
         * 1.Column 类似 LinearLayout 的垂直布局，用来进行垂直方向的布局
         *
         * 2. Row 类似 LinearLayout 的水平布局，用来进行水平方向的布局
         *
         * 3.Text 类似 TextView，用来显示文案
         *
         * 4.Image 类似 ImageView，用来展示图片
         *
         * 5. Modifier 用来处理样式修饰、手势、点击等
         */
        Row(
            modifier = Modifier
                // 设置内边距
                .padding(all = 8.dp)
                // 设置背景
                .background(MaterialTheme.colorScheme.background)
        ) {
            Image(
                painter = painterResource(R.drawable.profile_picture),
                contentDescription = null,

                modifier = Modifier
                    // 设置图片大小
                    .size(40.dp)
                    // 设置图片为圆形图片
                    .clip(CircleShape)
            )
            Column {
                Text(text = msg.author)
                // 设置两个视图间的间距
                Spacer(modifier = Modifier.height(4.dp))
                Text(text = msg.body)
            }
        }

    }

    @Preview
    @Composable
    fun PreviewMessageCard() {
        MessageCard(
            Message("Android", "Jetpack Compose")
        )
    }

    data class Message(
        val author: String,
        val body: String
    )
}
